package ee.siimkaspar.subjects.tests;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.junit.Test;

import ee.siimkaspar.subjects.model.*;
import ee.siimkaspar.subjects.service.UserService;
import ee.siimkaspar.subjects.validator.SubjectValidator;

public class ValidatorTests {
	private SubjectValidator sv = new SubjectValidator();
	private Address address = new Address();
	private Person person = new Person();
	private Enterprise enterprise = new Enterprise();
	private HashMap<String, String> expected;
	private HashMap<String, String> result;
	private List<EnterprisePersonRelation> enterprisePersonRelations = new ArrayList<EnterprisePersonRelation>();;
	private EnterprisePersonRelation epr = new EnterprisePersonRelation();
	private UserService us = new UserService();
	private UserAccount usResult = new UserAccount();
	
	@Test
	public void validateAddressTest(){
		address.setCountry("EstoniaEstoniaEstoniaEstoniaEstoniaEstoniaEstoniaEstonia");
		address.setCounty("");
		address.setTownVillage("Tallinn");
		address.setStreetAddress("Liivalaia 34A-11");
		expected = new HashMap<String, String>();
		expected.put("countryError", "Country's name must be between 1 to 50 characters.");
		expected.put("countyError", "County's name must be between 1 to 100 characters.");
		result = sv.validateAddress(address);
		assertEquals(expected, result);
	}
	@Test
	public void validateEnterpriseTest(){
		enterprise.setFullName("");
		enterprise.setName("");
		expected = new HashMap<String, String>();
		expected.put("fullNameError", "Enterprise's fullname must be between 1 and 255 characters");
		expected.put("nameError", "Enterprise's name must be between 1 and 255 characters");
		result = sv.validateEnterprise(enterprise);
		assertEquals(expected, result);
	}
	@Test
	public void validatePersonDeleteTest(){
		enterprisePersonRelations.add(epr);
		person.setEnterprisePersonRelations(enterprisePersonRelations);
		expected = new HashMap<String, String>();
		expected.put("personEnterpriseRelatsionError", "Person is tied to enterprise. Unable to delete.");
		result = sv.validatePersonDelete(person);
		assertEquals(expected, result);
	}
	@Test
	public void getAccountByUsernameAndPasswordTest(){
		String username = "juhan";
		String password = "asd";
		usResult = us.getAccountByUsernameAndPassword(username, password);
		System.out.println(usResult);
		assertEquals(usResult, null);
	}
}
